﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using V = Science.Mathematics.VectorCalculus;

namespace VectorCalculus5Ed.Chapter3.Section4
{
    public class Example02
    {
        public Example02()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
        public void Compute()
        {
            V.Function.ToLastType<double[], double> f
                = new V.Function.ToLastType<double[], double>(func);
            V.Function.ToLastType<double[], double[]> g
                = new V.Function.ToLastType<double[], double[]>(gf);
            double[] x = { 1.1, 1.1 };
            double[] l = { 1.1 };
            V.LagrangeMultiplierMethod obj
                = new V.LagrangeMultiplierMethod(f, g, x, l);
            obj.Compute();
            result += obj.CriticalPoint[0].ToString() + "\r\n";
            result += obj.CriticalPoint[1].ToString() + "\r\n";
            result += obj.LagrangeMultiplier[0].ToString() + "\r\n";
        }
        private double func(double[] x)
        {
            return x[0] * x[0] - x[1] * x[1];
        }
        private double[] gf(double[] x)
        {
            double[] y = new double[1];
            y[0] = x[0]*x[0] + x[1]*x[1] - 1.0;
            return y;
        }
    }
}

/*
0.999999999999449
-8.67496510889643E-07
1
*/